package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Client;
import cn.wolfcode.crm.service.IClientService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("clientPool")
public class ClientPoolController {
    @Autowired
    private IClientService clientService;

    @RequestMapping("view")
    public String view() {
        return "clientPool/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public List<Client> list() {
        List<Client> result = clientService.selectAllPoolClient();
        return result;
    }

    //将潜在池的客户移交给自己
    @RequestMapping("join")
    @ResponseBody
    public JsonResult join(Long clientId) {
        JsonResult result = new JsonResult();
        try {
            clientService.join(clientId);
        } catch (Exception e) {
            e.printStackTrace();
            return result.mark("移交失败");
        }
        return result;
    }

    @RequestMapping("dispatch")
    @ResponseBody
    public JsonResult dispatch(Long clientId, Long salemanId) {
        JsonResult result = new JsonResult();
        try {
            clientService.dispatch(clientId, salemanId);
        } catch (Exception e) {
            e.printStackTrace();
            return result.mark("移交失败");
        }
        return result;
    }
}
